/*
 * Copyright (c) TD-Tech Technologies Co., Ltd. 2024-2024. All rights reserved.
 */
import { LogDomain, LogHelper } from '@tdos/common';
import { image } from "@kit.ImageKit"
import { tdvision } from '@kit.TdosVisionKit'
import face = tdvision.face
import plate = tdvision.plate

const TAG = "KitDemo-AICarManager";
const logHelper: LogHelper = LogHelper.getLogHelper(LogDomain.DEBUG_MAIN, TAG);

// AI Car detector manager
export class AICarManager {

  private static instance: AICarManager = new AICarManager();
  static getInstance(): AICarManager {
    return AICarManager.instance;
  }

  private constructor() {
  }

  public async detectFacePixelMap(img: image.PixelMap): Promise<image.PixelMap[]> {
    let results: Array<image.PixelMap> = await face.detectFacePixelMap(img, img.getPixelBytesNumber())

    if (results !== null) {
      return results
    }
  }

  public async recognizeFacePixelMap(img: image.PixelMap): Promise<face.Face[]> {
    let results: face.Face[] = await face.recognizeFace(img, img.getPixelBytesNumber())

    if (results !== null) {
      return results
    } else {
      return []
    }
  }

  public async detectPlatePixelMap(img: image.PixelMap): Promise<image.PixelMap[] | null> {
    let results: Array<image.PixelMap> = await plate.detectPlatePixelMap(img, img.getPixelBytesNumber())
    if (results !== null) {
      return results
    }
  }

  public async parsePlatePixelMap(img: image.PixelMap): Promise<plate.Plate[] | null> {
    let results: Array<plate.Plate> = await plate.parsePlate(img, img.getPixelBytesNumber())
    if (results !== null) {
      logHelper.showError('parsePlatePixelMap successfully:'+JSON.stringify(results));
      return results
    } else {
      logHelper.showError('parsePlatePixelMap return null');
      return []
    }
  }

}